import java.util.ArrayList;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.*;


public abstract class Behaviour {
	String name;
	String path;
	Button button =null;
	ArrayList<AbstractElement> executionTree;
	
	public Behaviour(String name,String path){
		this.name = name;
		this.path = path;
		reload();
	}
	
	public void reload(){
		System.err.println("File loaded: "+path);
		executionTree = Parser.Parse(path);
	}
	
	abstract protected void select();
	
	public void startGUI(Composite parent) {
		if(button == null){
			button = new Button(parent, SWT.TOGGLE);
			button.setText(name);
			button.addSelectionListener(new SelectionListener() {

				@Override
				public void widgetSelected(SelectionEvent e) {
					// TODO Auto-generated method stub
					System.out.println(name+" selected");
					select();
				}

				@Override
				public void widgetDefaultSelected(SelectionEvent arg0) {
					// TODO Auto-generated method stub

				}
			});
		}
	}


	public void play(Robot robot) {
		try {
			for(AbstractElement ae: executionTree){
			
				ae.interpret((RobotActions)robot);
			}
		}
			
			catch (Exception e) {
				System.err.println("Behaviour: Error while trying to interpret");
				return;
			}
		
	}
}
